﻿using System;

namespace Polymorphism
{
    class Program
    {
        static void Main(string[] args)
        {
            Stock stock = new Stock
            {
                Name = "ThreeStocks",
                SharesOwned = 10000
            };
            Asset asset = stock;//向上转型

            //对象本身并不会为空，只是asset指向了Null
            //asset = null;
            //Console.WriteLine(stock.Name);
            if (asset is Stock s)
            {
                Console.WriteLine(s.SharesOwned);
            }



            //Stock stock1 = (Stock)asset;//向下转型
            //Console.WriteLine("向下转型测试：" + stock1.SharesOwned);
            //if (stock1 is Stock a)
            //{
            //    Console.WriteLine(a.SharesOwned);
            //}

        }

        static void DiaplayAsset(Asset asset)
        {
            Console.WriteLine(asset.Name);
        }
    }
    //资产的父类
    public class Asset
    {
        public string Name;
    }

    public class Stock : Asset // inherits from Asset
    {
        //拥有股份
        public long SharesOwned;
    }
    public class House : Asset // inherits from Asset
    {
        //抵押
        public decimal Mortgage;
    }
}
